﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework6_汉诺塔
{
    class Program
    {
        static int count = 0;
        static void Main(string[] args)
        {
            Console.Write("请输入圆盘的个数：");
            int num = Convert.ToInt32(Console.ReadLine());
            Move(num,"A","B","C");
            Console.WriteLine($"完成移动，共移动{count}次");
            Console.ReadKey();
        }
        /// <summary>
        /// 汉诺塔递归函数
        /// </summary>
        /// <param name="n"></param>
        /// <param name="a"></param>初始柱子
        /// <param name="b"></param>借助柱子
        /// <param name="c"></param>最终柱子
        static void Move(int n,string a,string b,string c)
        {
            if (n==1)
            {
                count++;
                Console.WriteLine($"第{count}次移动：把{n}号圆盘从柱子{a}移动到柱子{c}上");
            }
            else
            {
                //n-1个盘子从A移动到B上，以C为辅助塔
                //第n个盘子从A移到C
                //n-1个盘子从B移动到C上，以A为辅助塔
                Move(n - 1, a, c, b);
                count++;
                Console.WriteLine($"第{count}次移动：把{n}号圆盘从柱子{a}移动到柱子{c}上");
                Move(n - 1, b, a, c);
            }
        }
    }
}
